<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>测试websocket</title>
    <script type="text/javascript" src="goeasy-2.2.2.min.js"></script>
    <script type="text/javascript">
        var goeasy  = GoEasy.getInstance({
            host:"hangzhou.goeasy.io",  //若是新加坡区域：singapore.goeasy.io
            appkey:"BC-843388ae9cec402eb35090aae5383c7a",
            modules:['pubsub']//根据需要，传入‘pubsub’或'im’，或数组方式同时传入
        });

        goeasy.connect({
            id:"002", //pubsub选填，im必填
            data:{"avatar":"/www/xxx.png","nickname":"002"}, //必须是一个对象，pubsub选填，im必填，用于上下线提醒和查询在线用户列表时，扩展更多的属性
            onSuccess: function () {  //连接成功
                console.log("GoEasy connect successfully.") //连接成功
            },
            onFailed: function (error) { //连接失败
                console.log("Failed to connect GoEasy, code:"+error.code+ ",error:"+error.content);
            },
            onProgress:function(attempts) { //连接或自动重连中
                console.log("GoEasy is connecting", attempts);
            }
        });

        var pubsub = goeasy.pubsub;
        pubsub.subscribe({
            channels: ["my_channel","002"],//替换为您自己的channel
            onMessage: function (message) {
                document.getElementById("msgText").value=message.content;
                console.log("Channel:" + message.channel + " content:" + message.content);
            },
            onSuccess: function () {
                console.log("Channel订阅成功。");
            },
            onFailed: function (error) {
                console.log("Channel订阅失败, 错误编码：" + error.code + " 错误信息：" + error.content)
            }
        });
    </script>
</head>
<body>
  收到的信息 ：<input type="text" value="" id="msgText">
</body>
</html>